package main

import "sync"

func DispatchTasks(taskQueue chan Task, workerCount int) chan string {
	resultChan := make(chan string)
	var wg sync.WaitGroup
	for i := range workerCount {
		wg.Add(1)
		worker := Worker{
			ID:         i,
			TaskChan:   taskQueue,
			ResultChan: resultChan,
		}
		go worker.Start(&wg)
	}

	go func() {
		wg.Wait()
		close(resultChan)
	}()

	return resultChan
}
